import Taro from '@tarojs/taro';
import { View, Text, Block } from '@tarojs/components';
import PropTypes from 'prop-types';
import './index.scss'

export default class MoreFooter extends Taro.Component {
    static defaultProps = {
        moreType: 'none',
        showText: '上拉加载更多',
        resetloading: ()=>{},
        bg: '#f5f5f5',
        noMore: '没有更多了',
        loadingText: '加载中',
        loadingType: false,
        slotcontent: ''
    }
    render() {
        let { moreType, restloading, bg, noMore, loadingText, loadingType, showText, slotcontent } = this.props;
        return (
            <View>
                {moreType != 'none' &&
                    <View className='footer-box' onClick={() => { moreType === 'error' && restloading() }} style={{ backgroundColor: bg }}>
                        {moreType == 'showText' && <Text >{showText}</Text>}
                        {moreType == 'loading' &&
                            <Block>
                                {loadingType ?
                                    <Block >
                                        {slotcontent}
                                    </Block> :
                                    <Block >
                                        <View className='weui-loading'></View>{loadingText}
                                    </Block>
                                }
                            </Block>
                        }
                        {moreType == 'noMore' && <Text >{noMore}</Text>}
                        {moreType == 'error' && <Text >加载失败，<Text className='fc_FF0'>点击重试</Text> </Text>}
                    </View >
                }
            </View>

        )
    }
}

MoreFooter.propTypes = {
    moreType: PropTypes.string,
    restloading: PropTypes.func,
    bg: PropTypes.string,
    noMore: PropTypes.string,
    loadingText: PropTypes.string,
    loadingType: PropTypes.bool,
    showText: PropTypes.string,
    slotcontent: PropTypes.string,
}